import React, { Component } from 'react';
import { Modal, Form, message, Table, Badge } from 'antd';

export default class SelectDev extends Component {
    state = {
        selectedRowKeys: [],
        selectedRows: {},
    };
    onSelectChange = (selectedRowKeys, selectedRows) => {
        //console.log('selectedRowKeys changed: ', selectedRows);
        this.setState({ selectedRowKeys, selectedRows });
    };
    submit = () => {
        const { selectedRowKeys, selectedRows } = this.state;
        if (selectedRowKeys.length > 0) {
            //const matId = selectedRowKeys[0];
            this.props.setFormValue(selectedRows[0]);
        }
        this.props.handleModalVisible(false);
    };

    render() {
        const { modalVisible, handleModalVisible, data } = this.props;
        const { selectedRowKeys } = this.state;
        const rowSelection = {
            selectedRowKeys,
            onChange: this.onSelectChange,
            type: 'radio',
        };
        const columns = [
            {
                title: '设备ID',
                dataIndex: 'devUuid',
            },
            {
                title: '车牌号',
                dataIndex: 'vehLicplateNo',
            },

            {
                title: '设备名称',
                dataIndex: 'devName',

            },

            {
                title: '公司',
                dataIndex: 'compName',

            },
            {
                title: '主驾驶员',
                dataIndex: 'mainDriver',

            },
        ];
        return (
            <Modal
                title="选择报修设备"
                visible={modalVisible}
                onOk={this.submit}
                width={1000}
                onCancel={() => handleModalVisible(false)}
            >
                <Form>
                    <Table rowKey="devUuid" selections={false} rowSelection={rowSelection} dataSource={data} columns={columns} />
                </Form>
            </Modal>
        );
    }
}
